﻿namespace ScrumLite.Data.Tests
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Transactions;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using System.Collections.ObjectModel; 

    /// <summary>
    /// Summary description for UserStoreFixture
    /// </summary>
    [TestClass]
    public class UserStoreFixture
    {
        IUserStore store;

        [TestInitialize]
        public void Initialize()
        {
            store = new UserStore();
        }

        [TestMethod()]
        public void ShouldRetrieveUserEducation()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                using (ScrumLiteDataContext context = new ScrumLiteDataContext())
                {
                    context.Educations.InsertOnSubmit( new Education { id = Guid.NewGuid(),  samAccountName = "southy", title = "engineer", certificator = "stanford", completed = false } );
                    context.SubmitChanges();
                }

                Education[] education = store.RetrieveUserEducation("southy");

                Assert.IsTrue(education.Count() > 0);
            }
        }

        [TestMethod()]
        public void ShouldRetrieveUserAbilities()
        {
            using (TransactionScope scope = new TransactionScope())
            {
                using (ScrumLiteDataContext context = new ScrumLiteDataContext())
                {
                    Guid abilityId = Guid.NewGuid();
                    context.Abilities.InsertOnSubmit(new Ability { id = abilityId, name = "ASP.NET" });
                    context.SubmitChanges();
                    context.UserAbilities.InsertOnSubmit(new UserAbility { id = Guid.NewGuid(), fk_ability = abilityId, samAccountName = "southy" });
                    context.SubmitChanges();
                }

                Ability[] abilities = store.RetrieveUserAbilities("southy");

                Assert.IsTrue(abilities.Count() > 0);
            }
        }
    }
}
